package com.shop.wk.service.impl;

import com.shop.wk.common.constant.HttpCode;
import com.shop.wk.common.dto.ResponseResult;
import com.shop.wk.service.AuthServiceDubbo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices;

/**
 * @author 日月星辰
 * @date 2020/12/26 23:52
 * @description
 */
@DubboService(version = "1.0.0")
public class AuthServiceDubboImpl implements AuthServiceDubbo {

	@Autowired
	private ResourceServerTokenServices resourceServerTokenServices;

	@Override
	public ResponseResult checkToken(String token) {
		OAuth2AccessToken accessToken = resourceServerTokenServices.readAccessToken(token);
		if (accessToken != null) {
			return new ResponseResult(HttpCode.OK, "ok", accessToken.getExpiresIn());
		}
		return new ResponseResult(HttpCode.FAIL, "no");
	}

}
